Wireless printers offer a lot of flexibility in choosing where you place your printer and where you want to work. While they are becoming very popular it is not possible for everyone to have the luxury of a brand new wireless printer. Fortunately you can turn your printer into one with the help of Raspberry Pi. We will make use of the CUPS printing system and Avahi or Samba in doing.
CUPS is a printing system originally developed by Michael Sweet for Unix-like operating systems under the GNU General Public License(GPL) and now owned by Apple Inc. It uses the Internet Printing Protocol(IPP) that allows it to run locally over the internet.
Like all systems that run on the internet CUPS has client and server components. If you have a printer connected to your computer you need CUPS server to use it but for using a shared computer you only need the client. To make your printer available to a Windows machine you can install samba
In CUPS all print jobs are first sent to a scheduler. These jobs are forwarded to a filter system which does the necessary conversion of formats. A backend then sends this data to a printer or a network.
Avahi is a free software licensed under GPL that helps in advertising network services. It automates network generation using the zeroconf technology and is very useful in sharing resources over a network; in our case, a printer.
Samba is a cross-platform suite that ensures interoperability among Windows and Unix-like computers by providing services for clients using the SMB/CIFS protocol. In our case it lets us share our wireless printer with a Windows machine.
Step1 :- Ensure that you have internet connectivity and update the packages on your Raspberry Pi.
Commands :- sudo apt-get update sudo apt-get upgrade
Step2 :- Install the packages necessary for setting up a CUPS printing system.
Command :- sudo apt-get install avahi-daemon avahi-discover libnss-mdns cups cups-pdf python-cups Step3 :- Add your username on Raspberry Pi to the CUPS server. Command :- sudo usermod -aG lpadmin pi Step4 :- Check if CUPS and Avahi are properly installed. Commands :- sudo /etc/init.d/cups start sudo /etc/init.d/avahi-daemon start
Step 5 :- Configure CUPS
After ensuring everything is fine we shall set the port which is to be listened to. Open the cupsd.conf file and put a hash-tag in the beginning of the line that reads "Listen localhost:631" to comment it out. Add a new line that reads "Port 631". Another change to be made is to add * directive before <Location /> that follows the comment "# Restrict access to the server..." so as to let CUPS be used with any hostname. Finally add the lines "Order allow,deny" and "Allow @Local" after each comment that contains "Restrict access to". Save the new configuration file and restart cups.
Commands :- sudo nano /etc/cups/cupsd.conf sudo /etc/init.d/cups restart
Step 6 :- Enabling sharing of printer
Find the IP address of your Pi using ifconfig command and run it along with the port number to enter the CUPS web interface. Ignore any warnings and enter the "Admin" tab and enable sharing of printers.
Step 7 :- Setting up the local printer
The local printer can be easily set up by connecting it to a USB port and making use of the CUPS web interface. Fill in the required information and enable sharing of the printer. The web interface will then ask for drivers and settings. Enter them appropriately and take a print out of a test page.
Step 8:- Setting up Avahi (For Apple devices)
Create a directory airprint inside the /opt directory and move to that directory. Make use of wget to download a Python file that will help us generate the services required for wireless printing. take ownership of the file using chmod. Finally generate the services by placing the script in the avahi services folder. In case any error messages are displayed follow step 9.
Commands :- cd ../../opt sudo mkdir airprint cd airprint sudo wget -O airprint-generate.py --no-check-certificate https://raw.github.com/tjfontaine/airprint-generate/master/airprint-generate.py sudo chmod 755 airprint-generate.py sudo ./airprint-generate.py -d /etc/avahi/services
Step 9 :- Fixing errors
Go to /usr/share/cups/mime and create a file airprint.types. The content of the file shall be as given below. # # "$Id: $" # # AirPrint type image/urf urf string(0,UNIRAST) # # End of "$Id: $". #
Create another file airprint.convs with contents as given below.
# # "$Id: $" # # AirPrint # Updated list with minimal set 25 Sept image/urf application/pdf 100 pdftoraster # # End of "$Id: $". #
Restart CUPS and then repeat step 8. Reboot the Pi and start testing.
Commands :- sudo nano airprint.types sudo nano airprint.convs sudo service cups restart
Step 10 :- Installing samba (For devices running Windows)
Install samba using apt-get and check the samba configuration file in the /etc/samba directory. It must contain the following lines. The file is pretty long. Make use of 'ctrl+w'in nano to search for the lines.
# CUPS printing. See also the cupsaddsmb(8) manpage in the # cupsys-client package. printing = cups printcap name = cups [printers] comment = All Printers browseable = no path = /var/spool/samba printable = yes guest ok = yes read only = yes create mask = 0700 # Windows clients look for this share name as a source of downloadable # printer drivers [print$] comment = Printer Drivers path = /usr/share/cups/drivers browseable = yes read only = yes guest ok = no
Reboot and start testing.